var validLogInForm = [false];
var submitLogIn = document.getElementById('loginSubmit');

/* LogIn Validator */
    var loginUserName = document.getElementById('loginUserName');
    var loginPassWord = document.getElementById('loginPassWord');
    //check UserName
        loginUserName.addEventListener('focus', loginValidator, false);
        loginUserName.addEventListener('blur', loginValidator, false);
        loginUserName.addEventListener('keydown', loginValidator, false);
        loginUserName.addEventListener('keyup', loginValidator, false);
        loginUserName.addEventListener('click', loginValidator, false);
        loginUserName.addEventListener('mouseover', loginValidator, false);
        loginUserName.addEventListener('click', loginValidator, false);
    //check PassWord
        loginPassWord.addEventListener('focus', loginValidator, false);
        loginPassWord.addEventListener('blur', loginValidator, false);
        loginPassWord.addEventListener('keydown', loginValidator, false);
        loginPassWord.addEventListener('keyup', loginValidator, false);
        loginPassWord.addEventListener('click', loginValidator, false);
        loginPassWord.addEventListener('mouseover', loginValidator, false);
        loginPassWord.addEventListener('click', loginValidator, false);
    function loginValidator () {
        if ((loginUserName.value.length != 0) && (loginPassWord.value.length != 0)) {
            document.getElementById('errMsg_login').innerHTML = "";
            validLogInForm[0] = true;
        } else {
            document.getElementById('errMsg_login').innerHTML = "please fill in your username and password";
            validLogInForm[0] = false;
        }
        submissionAllower();
    }

function submissionAllower () {
    /* allow submit iff valid */
        var loginAllowed = true;

        for (var i = 0; i < validLogInForm.length; ++i) {
            if (! validLogInForm[i]) {loginAllowed = false; break;}
        }

        if (loginAllowed) {
            submitLogIn.disabled = false;
        } else {
            submitLogIn.disabled = true;
        }
}
